test: add unit tests for pkg/providers/embeddings package#202
test: add unit tests for pkg/providers/embeddings package#202mason5052 wants to merge 1 commit intovxcontrol:masterfrom
Conversation
Add unit tests for the embedding provider factory function covering all 7 supported providers (OpenAI, Ollama, Mistral, Jina, Huggingface, GoogleAI, VoyageAI), the none provider, unsupported provider error handling, custom URL/key/model configuration, and IsAvailable behavior.
There was a problem hiding this comment.
Pull request overview
Adds initial unit test coverage for the pkg/providers/embeddings factory to ensure all supported embedding providers (and error/none cases) are exercised.
Changes:
- Introduces
embedder_test.gowith per-provider tests forNew()across all supported providers. - Adds coverage for custom OpenAI URL/key/model configuration, the
"none"provider behavior, and unsupported provider error handling. - Adds a test for
IsAvailable()when the underlying embedder is nil.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| e, err := New(cfg) | ||
| require.NoError(t, err) | ||
| assert.NotNil(t, e) | ||
| assert.True(t, e.IsAvailable()) | ||
| } |
There was a problem hiding this comment.
assert.NotNil(t, e) doesn't stop the test, and the next line dereferences e via e.IsAvailable(). If New ever returns a nil embedder with a nil error (or the code changes), this will panic rather than produce a clean test failure. Use require.NotNil(t, e) (or guard the dereference) in this and the other tests in this file where e is used after an assert.NotNil.
| e, err := New(cfg) | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "unsupported embedding provider") | ||
| assert.NotNil(t, e) | ||
| assert.False(t, e.IsAvailable()) | ||
| } |
There was a problem hiding this comment.
In this test, assert.Error(t, err) and assert.Contains(t, err.Error(), ...) are used back-to-back. Since assert.Error doesn't stop execution, a nil err would cause a panic when calling err.Error(). Prefer require.Error(t, err) (or guard err before dereferencing) so failures are reported cleanly.
Description of Change
Problem: The
pkg/providers/embeddingspackage has no unit test coverage. This package provides the embedding provider factory supporting 7 providers (OpenAI, Ollama, Mistral, Jina, Huggingface, GoogleAI, VoyageAI) used for vector store operations.Solution: Add unit tests for the New() factory function covering all 7 supported providers, the "none" provider, unsupported provider error handling, custom URL/key/model configuration, and IsAvailable() behavior for both valid and nil embedders.
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
go test ./pkg/providers/embeddings/... -vTest Results
Checklist
go fmtandgo vetrun